// pages/order/orderReward/orderReward.js
var api = require("../../../api.js"),
    app = getApp(),
  WxParse = require('../../../wxParse/wxParse.js');
Page({
    /**
     * 页面的初始数据
     */
    data: {
        award: {},
        id: '',
    },
    // getAwardHandler 获取奖励
    getAwardHandler: function(e) {
        var that = this;
        app.request({
            url: api.driver.receive,
            method: 'post',
            data: {
                id: that.data.id
            },
            success: function(rs) {
                wx.showToast({
                    title: rs.msg,
                })
            }
        })
        /* const current_award = this.data.award;
         if (current_award.status) {
             current_award.status = false;
             const award = wx.getStorageSync("award");
             for (var i = 0; i < award.length; i++) {
                 award[i].status = award[i].id === current_award.id ? false : award[i].status;
             }
             wx.setStorageSync("award", award);
             this.setData({
                 award: current_award
             });
             wx.showToast({
                 title: '领取成功',
             })
         } else {
             wx.showToast({
                 title: '你已领取奖励',
             })
         }*/
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        console.log('奖励详情', options)
        this.setData({
            id: options.id
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        var that = this;
        app.request({
            url: api.driver.details,
            method: 'post',
            data: {
                id: that.data.id
            },
            success: function(rs) {
                that.setData({
                    award: rs.data
                })
              WxParse.wxParse('active', 'html', rs.data.remark, that, 5)
            }
        })
        /* this.setData({
             award: wx.getStorageSync("current_award")
         });*/
    },
})